package com.hsy.linemoney.apiservice;

import com.deparse.dpframe.tools.utils.DPGsonUtil;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * Paypal相关
 * Created by MartinKent on 2016/10/9.
 */

public class PaypalService extends BasicService<JSONArray> {
//    获取PayPal状态
    public void getPaypalStatus(String orderId, final Callback<PaypalStatusResult> callback) {
        String api = "/LmBusinessServices-portlet.paypalrecord/get-paypal-status";
        JSONObject params = ParamsMaker.newInstance().add("orderId", orderId).get();
        invoke(0, api, params, new Callback<JSONArray>() {
            @Override
            public void onSuccess(int what, JSONArray result) {
                if (null != callback) {
                    try {
                        callback.onSuccess(what, DPGsonUtil.fromJson(result.get(0).toString(), PaypalStatusResult.class));
                    } catch (JSONException e) {
                        e.printStackTrace();
                        callback.onError(what, 0, e.getLocalizedMessage(), e);
                    }
                }
            }

            @Override
            public void onError(int what, int type, String msg, Exception e) {
                if (null != callback) {
                    callback.onError(what, 0, e.getLocalizedMessage(), e);
                }
            }
        });
    }

    public static class PaypalStatusResult {
        private Status status;

        public void setStatus(Status status) {
            this.status = status;
        }

        public Status getStatus() {
            return this.status;
        }

        public static class Status {
            private String message;

            private String code;

            public void setMessage(String message) {
                this.message = message;
            }

            public String getMessage() {
                return this.message;
            }

            public void setCode(String code) {
                this.code = code;
            }

            public String getCode() {
                return this.code;
            }

        }
    }
}
